use strict;
use warnings;

use File::Spec;
use FindBin;
use lib File::Spec->catfile($FindBin::RealBin, qw/.. lib/);
use Test::More;
use List::MoreUtils qw/true/;

use Lingua::EN::WSD::WebBased::Expander::Google;

my $e = new Lingua::EN::WSD::WebBased::Expander::Google;

plan skip_all => 'Could not get access to Google'
    if !defined eval { $e->expand(['b']) };

plan tests => 7;

my $documents;

$documents = $e->expand(['a']);
is @$documents, 32, 'simple query "a"';
ok ((true { /<b>a<\/b>/i } @$documents) > 20, 'simple assertion on query "a"');

ok -f $e->cache_file, 'check existence of cache file';
ok exists $e->cache->{'a'}, 'check existence of cache entry';
is_deeply $e->hit_in_cache('a'), $documents, 'check consistence of cache';

$documents = $e->expand(['kaslfkjaslfdkjsaldkjflkjaslkfjlaksdjflkjasdfkjlsa']);
is @$documents, 0, 'query supposed to return empty result';

$e->expansion_size(5);
$documents = $e->expand(['a']);
is @$documents, 5, 'simple query "a" with specified expansion_size';

unlink $e->cache_file if -f $e->cache_file;

